package com.blog.sys.shiro.realm;

import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;

/**
 * shiro
  * <p>Title: CredentialMatcher </p>  
  * <p>Description:自定义密码校验规则 ,在shiro的config中使用</p>
  * @author yanakai@126.com  
  * @date 2019年7月2日
 */
public class CredentialMatcher extends SimpleCredentialsMatcher {
	@Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        UsernamePasswordToken usernamePasswordToken = (UsernamePasswordToken) token;
        String password = new String(usernamePasswordToken.getPassword());
        String dbPassword = (String) info.getCredentials();
        return this.equals(password, dbPassword);
    }
}
